//
//  RadioDetailViewController.m
//  IFengNews
//
//  Created by lanou3g on 16/3/8.
//  Copyright © 2016年 徐强. All rights reserved.
//

#import "RadioDetailViewController.h"
#import "RadioDetailModel.h"
#import "UrlRequestManager.h"
#import "RadioDetailTableViewCell.h"
#import "UIImageView+WebCache.h"
@interface RadioDetailViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong)NSMutableArray *arrAllData;
@end

@implementation RadioDetailViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    [self requestData];
    [self initView];
}
- (void)initView{
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"RadioDetailTableViewCell" bundle:nil] forCellReuseIdentifier:@"RadioDetailTableViewCell"];
}
- (void)requestData{
    [UrlRequestManager requestWith:GET URL:self.detailUrl condition:nil SuccessBlock:^(id item) {
        for (NSDictionary *dic in item[@"tList"]) {
            RadioDetailModel *model = [[RadioDetailModel alloc]init];
            [model setValuesForKeysWithDictionary:dic];
            [model setValuesForKeysWithDictionary:dic[@"radio"]];
            [self.arrAllData addObject:model];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tableView reloadData];
        });
    } failBlock:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}
- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arrAllData.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    RadioDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RadioDetailTableViewCell" forIndexPath:indexPath];
    RadioDetailModel *model = self.arrAllData[indexPath.row];
    cell.title.text = model.title;
    cell.tName.text = model.tname;
    cell.playCount.text = [NSString stringWithFormat:@"%ld",model.playCount];
    [cell.imgsrcV sd_setImageWithURL:[NSURL URLWithString:model.imgsrc]];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.1;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    /*
     第一行：http://image.kaolafm.net/mz/audios/201603/10e93fd6-12b7-4119-869b-b37bcfdee05c.mp3
     */
}
#pragma mark - 懒加载
- (NSMutableArray *)arrAllData{
    if (!_arrAllData) {
        _arrAllData = [NSMutableArray array];
    }
    return _arrAllData;
}


@end
